using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.ComponentModel;

namespace Omniture.API
{
	public enum DataTypeConstants
	{
		String,
		Int,
	}

	public class EVarItem : TrackItemBase
	{
		#region Class Members

		private const bool _def_isRequired = false;

		private string _defaultValue = "";
		private bool _isRequired = _def_isRequired;
		private DataTypeConstants _dataType = DataTypeConstants.String;

		#endregion

		#region Constructors

		public EVarItem(TrackItemCollection parent, int id)
			: base(parent,id)
		{			
		}

		#endregion

		#region Property Implementations

		[Browsable(false)]
		public override TrackItemConstants ItemType
		{
			get { return TrackItemConstants.EVar; }
		}

		[Browsable(true)]
		[Description("Determines the default value of this object at runtime")]		
		[Category("General")]
		public string DefaultValue
		{
			get { return (this.IsRequired) ? "" : _defaultValue; }
			set { _defaultValue = value; }
		}

		[Browsable(true)]
		[Description("Determines if the object is required to be set at runtime")]
		[DefaultValue(_def_isRequired)]
		[Category("General")]
		public bool IsRequired
		{
			get { return _isRequired; }
			set { _isRequired = value; }
		}

		[Browsable(false)]
		[Description("Determines the data type of the generated object")]
		[DefaultValue(typeof(DataTypeConstants), "String")]
		[Category("General")]
		public DataTypeConstants DataType
		{
			get { return _dataType; }
			set { _dataType = value; }
		}

		#endregion

		#region Methods

		#endregion

		#region IXmlable Members

		public override void LoadXml(System.Xml.XmlNode parentNode)
		{
			base.LoadXml(parentNode);
			_isRequired = XmlHelper.GetAttribute(parentNode, "IsRequired", _isRequired);
			_defaultValue = XmlHelper.GetAttribute(parentNode, "DefaultValue", _defaultValue);
			_dataType = (DataTypeConstants)Enum.Parse(typeof(DataTypeConstants), XmlHelper.GetAttribute(parentNode, "DataType", _dataType.ToString("d")));
		}

		public override void SaveXml(System.Xml.XmlNode parentNode)
		{
			base.SaveXml(parentNode);
			XmlHelper.AddAttribute(parentNode, "IsRequired", this.IsRequired.ToString());
			XmlHelper.AddAttribute(parentNode, "DefaultValue", this.DefaultValue);
			XmlHelper.AddAttribute(parentNode, "DataType", this.DataType.ToString("d"));
		}

		#endregion

	}
}